//创建图片
function creatImg(name: string) {
    let result = new egret.Bitmap();
    let texture: egret.Texture = RES.getRes(name);
    result.texture = texture;
    return result;
}

//创建文本
function creatText(text, fontSize, textColor, img,width,height,center="center") {
    let result = new egret.Sprite();
    let startImg = new egret.Bitmap();
    startImg.texture = RES.getRes(img);
    result.addChild(startImg);
    let btnText = new egret.TextField();
    btnText.text = text;
    btnText.size = fontSize;
    btnText.fontFamily = 'Microsoft YaHei';
    btnText.textColor = textColor;
    btnText.width = width;
    btnText.height = height;
    btnText.textAlign = center;
    btnText.verticalAlign = "middle";
    result.addChild(btnText);
    return result;
}

//创建矩形
function creatRect(x, y, width, height, bgColor, borderWidth, borderColor) {
    let result = new egret.Sprite();
    result.x = x;
    result.y = y;
    let btnShape = new egret.Shape();
    btnShape.graphics.lineStyle(borderWidth, borderColor);
    btnShape.graphics.beginFill(bgColor, 1);
    btnShape.graphics.drawRect(0, 0, width, height);
    btnShape.graphics.endFill();
    result.addChild(btnShape);
    return result;
}

//btnColor = 0xfff530   borderColor = 0xff9f34
function creatShape(x, y, width, height, text, picture, fontSize, textColor, btnColor = 0xffffff, borderWidth = 10, borderColor = 0xdbdcdc) {
    //创建矩形
    let result = new egret.Sprite();
    result.x = x;
    result.y = y;
    let btnShape = new egret.Shape();
    btnShape.graphics.beginFill(btnColor, 1);
    btnShape.graphics.lineStyle(borderWidth, borderColor);
    btnShape.graphics.drawRect(0, 0, width, height);
    btnShape.graphics.endFill();
    result.addChild(btnShape);

    //创建文本
    let btnText = new egret.TextField();
    btnText.text = text;
    btnText.size = fontSize;
    btnText.y = -10;
    btnText.textColor = textColor;
    btnText.width = width;
    btnText.height = height;
    btnText.fontFamily = 'Microsoft YaHei';
    btnText.textAlign = "center";
    btnText.verticalAlign = "bottom";
    result.addChild(btnText);

    //创建奖品图片
    let awardImg = new egret.Bitmap();
    awardImg.texture = RES.getRes(picture);
    awardImg.anchorOffsetX = awardImg.width*0.5;
    awardImg.anchorOffsetY = awardImg.height*0.5;
    awardImg.x = 88;
    awardImg.y = 60;
    result.addChild(awardImg);


    return result;
}

function creatBox(x,y,btnColor = 0xffffff,borderColor = 0xdbdcdc,borderWidth = 10,width = 170,height = 170){
    let result = new egret.Sprite();
    result.x = x;
    result.y = y;
    let btnShape = new egret.Shape();
    btnShape.graphics.beginFill(btnColor, 1);
    btnShape.graphics.lineStyle(borderWidth, borderColor);
    btnShape.graphics.drawRect(0, 0, width, height);
    btnShape.graphics.endFill();
    result.addChild(btnShape);
}


